//
//  QXGuideCell.m
//  QXWeibo2
//
//  Created by QinXin on 15/7/1.
//  Copyright © 2015年 labi3285_Lab. All rights reserved.
//

#import "QXGuideCell.h"
#import <Masonry/Masonry.h>
#import "QXAccount.h"
#import "QXMainVC.h"
#import "QXOAuthVC.h"

@interface QXGuideCell ()
@property (nonatomic, strong) UIImageView *imgV;
@property (nonatomic, strong) UIButton *btn;
@end

@implementation QXGuideCell

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self addSubview:self.imgV];
        [self addSubview:self.btn];
        
        // 约束
        __weak typeof(self) ws = self;
        
        [self.imgV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(ws);
        }];
        
        [self.btn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(ws);
            make.bottom.equalTo(ws).with.offset(-100);
        }];
    }
    return self;
}

- (UIImageView *)imgV {
    if (!_imgV) {
        _imgV = [[UIImageView alloc] init];
        [self addSubview:_imgV];
    }
    return _imgV;
}

- (UIButton *)btn {
    if (!_btn) {
        _btn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_btn setBackgroundImage:[UIImage imageNamed:@"new_feature_finish_button"] forState:UIControlStateNormal];
        [_btn setBackgroundImage:[UIImage imageNamed:@"new_feature_finish_button_highlighted"] forState:UIControlStateHighlighted];
        [_btn setTitle:@"点击进入" forState: UIControlStateNormal];
        
        [_btn addTarget:self action:@selector(btnClicked) forControlEvents:UIControlEventTouchUpInside];
    }
    return _btn;
}

- (void)setPicName:(NSString *)picName {
    _picName = picName;
    self.imgV.image = [UIImage imageNamed:picName];
    [_btn setHidden:YES];
}

- (void)showBtn {
    
    [self.btn setHidden:NO];
    
    self.btn.transform = CGAffineTransformMakeScale(0, 0);
    
    [UIView animateWithDuration:1.0 delay:0 usingSpringWithDamping:0.7 initialSpringVelocity:5 options:UIViewAnimationOptionCurveEaseIn animations:^{
        
        self.btn.transform = CGAffineTransformMakeScale(1.0, 1.0);
    } completion:nil];
    
}

- (void)btnClicked {
    if ([QXAccount sharedAccount] != nil) {
        [[NSNotificationCenter defaultCenter] postNotificationName:@"QXAppDelegateNeedsChangeViewController" object:self userInfo:@{@"class": [QXMainVC class]}];
    } else {
        [[NSNotificationCenter defaultCenter] postNotificationName:@"QXAppDelegateNeedsChangeViewController" object:self userInfo:@{@"class": [QXOAuthVC class]}];
    }
}

@end
